<template>
  <el-container>
    <el-header>
      <el-row>
        <el-col :span="3"
          ><div class="grid-content bg-purple">logo</div></el-col
        >
        <el-col :span="18"
          ><div class="grid-content bg-purple-light">
            <h1>后台管理系统</h1>
          </div></el-col
        >
        <el-col :span="3"
          ><div class="grid-content bg-purple" @click="open">
            <el-button type="text"> {{ userinfo.username }}</el-button>
          </div></el-col
        >
      </el-row>
    </el-header>
    <el-container class="Homeheigt">
      <el-aside width="200px">
        <el-col :span="24">
          <el-menu
            default-active="2"
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            :unique-opened="true"
            :router="true"
          >
            <el-submenu
              :index="item.path"
              v-for="(item, key) in menuData"
              :key="key"
            >
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item-group
                :index="itemS.path"
                v-for="(itemS, k) in item.children"
                :key="k"
              >
                <el-menu-item :index="itemS.path">
                  {{ itemS.authName }}</el-menu-item
                >
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-col>
      </el-aside>
      <el-main>
        <router-view> </router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      userinfo: {},
      menuData: [],
      // router: true,
    };
  },
  methods: {
    open() {
      this.$confirm("是否确定退出?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "退出成功!",
          });
          localStorage.removeItem("userinfo");
          this.$router.push("/login");
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消退出",
          });
        });
    },
  },
  mounted() {
    this.userinfo = JSON.parse(localStorage.getItem("userinfo"));

    this.$Req.get("/menus").then((res) => {
      const { data, meta } = res.data;
      this.menuData = data;
    });
    this.$router.push("/");
  },
};
</script>

<style>
.Homeheigt {
  height: 700px;
}
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
}
</style>